package com.blueocean_health.care.management.transfer.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.blueocean_health.care.management.domain.base.SysResult;
import com.blueocean_health.care.management.domain.base.User;
import com.blueocean_health.care.management.domain.dto.NurseGroupDto;
import com.blueocean_health.care.management.em.GroupDeflagEnum;
import com.blueocean_health.care.management.exception.OrderException;
import com.blueocean_health.care.management.service.NurseGroupService;

/**
 * @Author ChenPeng cp
 * @Date 2018/1/3 15:37
 */

@RestController
@RequestMapping(value = {"nurse/group","test/nurse/group"}, produces = MediaType.APPLICATION_JSON_VALUE)
public class NurseGroupController {

    @Autowired
    private NurseGroupService nurseGroupService;

    @RequestMapping("/add")
    public SysResult insertNurseGroup(@RequestBody String jsonStr) throws OrderException {
    	JSONObject jsonObject = JSONObject.parseObject(jsonStr);
    	NurseGroupDto nurseGroupDto = jsonObject.getObject("nurseGroupDto", NurseGroupDto.class);
		User courrentUser = jsonObject.getObject("currentUserInfo", User.class);
		
        String hid =  courrentUser.getHospitalId();
        nurseGroupDto.setHospitalId(hid);
        SysResult sysResult = nurseGroupService.addNurseGroup(nurseGroupDto);
        return sysResult;
    }


    @RequestMapping("/delete")
    public SysResult deleteNurseGroup(@RequestBody String jsonString) throws OrderException {
        JSONObject jsonObject =  JSONObject.parseObject(jsonString);
        Integer groupId = (Integer) jsonObject.get("groupId");
        return nurseGroupService.updateNurseGroupDeflag(groupId, GroupDeflagEnum._1.getKey());
    }

}
